package vip.zhenzicheng.jpa.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zhenzicheng
 * @date 2023-04-17 16:00
 */
@Configuration
@EnableSwagger2
public class Knife4jConfig {

    @Value("${knife4j.basePackage}")
    private String basePackage;

    @Bean(value = "dataApi")
    public Docket authApi() {
        System.out.println("basePackage:" + basePackage);

        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                // 这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("数据智能融合平台API")
                .description("# 对外接口API")
                .termsOfServiceUrl("http://swagger.io/")
                .contact(new Contact("dylan", "", ""))
                .version("1.0")
                .build();
    }
}
